module StoreFront
  module CBT  
    def self.onlineNode(nodes_N, port="8080")
            puts "StoreFront::CBT::onlineNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"  
            puts "etcd: #{$storeDeplConfig['etcdIP']}>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
            nodes_N.each do |node|              
                     response=system("curl -L http://#{$storeDeplConfig['etcdIP']}:4001/v2/keys/php/#{node} -XPUT -d value=#{port}")
                     puts "add node #{node} to router witch watched etcd .............."
            end
            puts "StoreFront::CBT::offlineNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
    end
    
    def self.offlineNode(nodes_N)
            puts "StoreFront::CBT::offlineNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" 
            puts "etcd: #{$storeDeplConfig['etcdIP']}>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"          
            nodes_N.each do |node|
                          response=system("curl -L http://#{$storeDeplConfig['etcdIP']}:4001/v2/keys/php/#{node} -XDELETE")
                          puts "add node #{node} to router witch watched etcd .............."
            end
            puts "StoreFront::CBT::offlineNode>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
    end  
    
    def self.extractChange()
      
    end  
    
    def self.syncChange(nodes_N, source, buildlable)
            
    end
    
    def self.moveNodeToPreRL(prodRouters_N, preRouters_N, nodes_N)
           #the move should be one by one
           # 1. offlineNode On Prod environment
           # 2. if builelable is not nil will do syncChange command to sync change to targetNode
           # 3. onlineNode on PreRL 
    end
    
    
    def self.moveNodeToProd(preRouters_N, prodRouters_N, nodes_N)
           #1. offlineNode on PreRL 
           #2. onlineNode on Prod
    end
    
  end
end